package com.dys.designpattern.simplefactory.dstributeprizes.controller;

import com.alibaba.fastjson2.JSON;
import com.dys.designpattern.simplefactory.dstributeprizes.entity.AwardInfo;
import com.dys.designpattern.simplefactory.dstributeprizes.entity.DiscountResult;
import com.dys.designpattern.simplefactory.dstributeprizes.entity.SmallGiftInfo;
import com.dys.designpattern.simplefactory.dstributeprizes.service.DiscountService;
import com.dys.designpattern.simplefactory.dstributeprizes.service.SmallGiftService;
import com.dys.designpattern.simplefactory.dstributeprizes.service.YouKuMemberService;

import java.util.UUID;

/**
 * @Author: 疾风
 * @ClassName: DeliverController
 * @Description: 按照类型的不同发放商品：奖品类型: 1 打折券 ,2 优酷会员,3 小礼品
 * @CreateDate: 2024/05/11
 * @Version: v1.0.0
 */
public class DeliverController {

    /**
     * 按照不同的类型，发放不同的商品：1.打折券 2.优酷会员 3.小礼品
     *
     * @param awardInfo 获奖信息
     */
    public void awardToUser(AwardInfo awardInfo) {

        if (awardInfo.getAwardType() == 1) {
            DiscountService discountService = new DiscountService();
            DiscountResult result = discountService.sendDiscount(awardInfo.getUid(), awardInfo.getAwardNumber());
            System.out.println("打折券发放成功!" + JSON.toJSON(result));
        } else if (awardInfo.getAwardType() == 2) {
            // 获取手机号
            String phone = awardInfo.getExtMap().get("phone");
            YouKuMemberService youKuMemberService = new YouKuMemberService();
            youKuMemberService.openMember(phone, awardInfo.getAwardNumber());
            System.out.println("优酷会员发放成功!");
        } else if (awardInfo.getAwardType() == 3) {
            // 封装收货用户信息
            SmallGiftInfo smallGiftInfo = new SmallGiftInfo();
            smallGiftInfo.setUserName(awardInfo.getExtMap().get("username"));
            smallGiftInfo.setOrderId(UUID.randomUUID().toString());
            smallGiftInfo.setRelAddress(awardInfo.getExtMap().get("address"));

            SmallGiftService smallGiftService = new SmallGiftService();
            Boolean b = smallGiftService.giveSmallGift(smallGiftInfo);
            System.out.println("小礼品发放成功!" + b);
        } else {
            System.out.println("没有优惠");
        }
    }
}
